home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / vg-2.03 / pcd / pcdcolor.c < prev   
Encoding:
Text File  |  1995-05-03  |  1.6 KB  |  73 lines

  1. /* hpcdtoppm (Hadmut's pcdtoppm) v0.5pl1
  2. *  Copyright (c) 1992, 1993 by Hadmut Danisch (danisch@ira.uka.de).
  3. *  Permission to use and distribute this software and its
  4. *  documentation for noncommercial use and without fee is hereby granted,
  5. *  provided that the above copyright notice appear in all copies and that
  6. *  both that copyright notice and this permission notice appear in
  7. *  supporting documentation. It is not allowed to sell this software in 
  8. *  any way. This software is not public domain.
  9. */
  10.  
  11.  
  12. int RGB_Maximum1=1023;
  13.  
  14.  
  15. int RGB_F_LL=1391;
  16. int RGB_F_C1=2271;
  17. int RGB_O_C1=-353784;
  18. int RGB_F_C2=1865;
  19. int RGB_O_C2=-255023;
  20. int RGB_F_G1=-441;
  21. int RGB_F_G2=-949;
  22. int RGB_O_G =199313;
  23.  
  24.  
  25. static int T_L[256],T_R[256],T_G[256],T_g[256],T_B[256];
  26.  
  27.  
  28. void
  29. pcd_to_rgb(
  30.     unsigned char    *pl,
  31.     unsigned char    *pc1,
  32.     unsigned char    *pc2,
  33.     unsigned char    *prgb,
  34.     int            n
  35.     )
  36. {
  37.     int        red, green, blue;
  38.     int        L;
  39.     static int    init    = 0;
  40.  
  41.     if (! init)
  42.     {
  43.     int    i;
  44.  
  45.     for (i = 0; i < 256; i++)
  46.     {
  47.         T_L[i] = i * RGB_F_LL;
  48.         T_R[i] = i * RGB_F_C2 + RGB_O_C2;
  49.         T_G[i] = i * RGB_F_G1;
  50.         T_g[i] = i * RGB_F_G2 + RGB_O_G;
  51.         T_B[i] = i * RGB_F_C1 + RGB_O_C1;      
  52.     }
  53.     init    = 1;
  54.     }
  55.  
  56.     while (--n >= 0)
  57.     {
  58.     L    =  T_L[*pl]; 
  59.     red  = (L + T_R[*pc2]             ) >> 10;
  60.     green= (L + T_G[*pc1] + T_g[*pc2] ) >> 10; 
  61.     blue = (L + T_B[*pc1]             ) >> 10;
  62.  
  63.     prgb[0]    = (red   & ~0xff) ? (red   < 0 ? 0 : 255) : red;
  64.     prgb[1]    = (green & ~0xff) ? (green < 0 ? 0 : 255) : green;
  65.     prgb[2]    = (blue  & ~0xff) ? (blue  < 0 ? 0 : 255) : blue ;
  66.  
  67.     prgb    += 3;
  68.     pl++;
  69.     pc1++;
  70.     pc2++;
  71.     }
  72. }
  73.